package com.manager.commons.utils;


public class GetterSetterGenerator {

    public static String generateGetter(String fieldName, String type) {
        String methodName = "get" + capitalize(fieldName);
        return String.format("public %s %s() { return this.%s; }", type, methodName, fieldName);
    }

    public static String generateAttribute(String fieldName, String type, String columnComment) {
        return String.format("private %s %s;//%s", type, fieldName, columnComment);
    }

    public static String generateSetter(String fieldName, String type) {
        String methodName = "set" + capitalize(fieldName);
        return String.format("public void %s(%s %s) { this.%s = %s; }",
                methodName, type, fieldName, fieldName, fieldName);
    }

    public static String getJavaType(String mysqlType) {
        String type = mysqlType.toLowerCase();
        String s = "";
        if (type.equals("tinyint")) {
            s = "Byte";
        } else if (type.equals("smallint")) {
            s = "Short";
        } else if (type.equals("mediumint") || type.equals("int")) {
            s = "int";
        } else if (type.equals("integer")) {
            s = "Integer";
        } else if (type.equals("bigint")) {
            s = "Long";
        } else if (type.equals("float")) {
            s = "Float";
        } else if (type.equals("double")) {
            s = "Double";
        } else if (type.equals("decimal") || type.equals("numeric")) {
            s = "BigDecimal";
        } else if (type.equals("boolean") || type.equals("bool")) {
            s = "Boolean";
        } else if (type.equals("date") || type.equals("time") || type.equals("timestamp")) {
            s = "Date";
        } else if (type.equals("blob") || type.equals("binary") || type.equals("varbinary")) {
            s = "byte[]";
        } else {
            s = "String";
        }
        return s;

    }


    private static String capitalize(String str) {
        if (str == null || str.isEmpty()) return str;
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

}
